package com.xbfinance.portal.service.impl;

import com.xbfinance.portal.dao.P2pAccountRechargeMapper;
import com.xbfinance.portal.pojo.po.P2pAccountRecharge;
import com.xbfinance.portal.service.PortalRechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.UUID;

@Service
@Transactional
public class PortalRechargeServiceImpl implements PortalRechargeService {
    @Autowired
    private P2pAccountRechargeMapper p2pAccountRechargeMapper;
    @Override
    public int saveRecharge(P2pAccountRecharge p) {
        //service  billno fee addtime
        int i = 0;
        try {
            p.setBillno(UUID.randomUUID().toString());
            //p.setBillno("aaa");
            p.setStatus((byte)0);
            double fee = p.getMoney()*0.05;
            DecimalFormat df = new DecimalFormat("#.00");
            String feeStr = df.format(fee);
            double d = Double.parseDouble(feeStr);
            p.setFee(d);
            p.setAddtime(new Date());
            i= p2pAccountRechargeMapper.insertSelective(p);
            System.out.println(8888);

        }catch (Exception e){
            e.printStackTrace();

        }
        return i;



    }
}
